package com.nexus.all.scheduled;

import com.nexus.all.es.service.EsNoteService;
import com.nexus.all.mongodb.service.MongoNoteHistoryService;
import com.nexus.all.service.IFileBatchService;
import com.nexus.all.service.UserTimeMailService;
import com.nexus.bean.utils.LogUtils;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


@Slf4j
@EnableScheduling
@Component
@EnableAsync
@AllArgsConstructor
public class NexusAllSchedule {

    private final UserTimeMailService userTimeMailService;
    private final IFileBatchService fileBatchService;
    private final EsNoteService esNoteService;
    private final MongoNoteHistoryService mongoNoteHistoryService;

    /**
     * 处理发送时间邮件
     * 每分钟执行一次
     *
     * @Async+@Scheduled 定时任务不阻塞功能，让定时任务开异步线程执行
     */
    @Async
    //@Scheduled(cron = "0/30 * * * * ?")
    @Deprecated
    public void dealSendUserTimeMail() {
        LogUtils.putJobTraceId();
        log.info("定时处理 时间邮件任务 开始..........");
        userTimeMailService.dealSendUserTimeMail();
        log.info("定时处理 时间邮件任务 结束..........");
    }

    /**
     * 处理待上传的文件
     *
     * @Async+@Scheduled 定时任务不阻塞功能，让定时任务开异步线程执行
     */
    @Async
    //@Scheduled(cron = "0 0/1 * * * ?")
    @Deprecated
    public void dealPendingFileBatch() {
        LogUtils.putJobTraceId();
        log.info("定时处理 上传文件 开始..........");
        fileBatchService.dealPendingFileBatch(null, LogUtils.getTraceId());
        log.info("定时处理 上传文件 结束..........");
    }


    @Async
    //@Scheduled(cron = "0 0/10 * * * ?")
    @Deprecated
    public void dealSyncNoteToEs() {
        LogUtils.putJobTraceId();
        log.info("定时处理 同步笔记到ES 开始..........");
        Integer num = esNoteService.dealSyncNoteToEs();
        log.info("定时处理 同步笔记到ES 结束 同步数量:{}.......", num);
    }

    @Async
    //@Scheduled(cron = "0 0 * * * ?")
    @Deprecated
    public void dealNoteBrowseNum() {
        LogUtils.putJobTraceId();
        log.info("定时处理 同步笔记浏览量 开始..........");
        mongoNoteHistoryService.dealNoteBrowseNum();
        log.info("定时处理 同步笔记浏览量 结束.......");
    }
}

